﻿using Ross.EntityFramework;
using Ross.Service;
using Ross.Service.Dto;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Net;
using System.Net.Http;
using System.Web.Http;
using System.Web.Http.Results;
using System.Web.Mvc;

namespace Ross.BSCSystem.Controllers
{
    [SimpleAuthenticationFilter]
    public class BSCReports_CoController : BaseApiController
    {
        /// <summary>
        /// 获取公司报表.
        /// </summary>
        /// <returns></returns>
        [System.Web.Http.HttpGet]
        public JsonResult<ResultDto<List<Service.Dto.BSCReports_CoOut>>> GetReports_Co(string ver = "")
        {
            ResultDto<List<Service.Dto.BSCReports_CoOut>> results = new ResultDto<List<Service.Dto.BSCReports_CoOut>>();
            using (BSCReports_DpService serv = new BSCReports_DpService(dbContextStr))
            {
                results = serv.GetReports(ver);
            }
            return Json(results);
        }

        /// <summary>
        /// 获取公司报表.
        /// </summary>
        /// <returns></returns>
        [System.Web.Http.HttpGet]
        public JsonResult<ResultDto<List<Service.Dto.BSCReports_DpOut>>> GetReports_Dp(string ver="", string name="")
        {
            ResultDto<List<Service.Dto.BSCReports_DpOut>> results = new ResultDto<List<Service.Dto.BSCReports_DpOut>>();
            using (BSCReports_DPService serv = new BSCReports_DPService(dbContextStr))
            {
                results = serv.GetReports(ver, name);
            }
            return Json(results);
        }

        /// <summary>
        /// 获取审核中.
        /// </summary>
        /// <returns></returns>
        [System.Web.Http.HttpGet]
        public JsonResult<ResultDto<List<Service.Dto.ShenHeOutput>>> Approval()
        {
            ResultDto<List<Service.Dto.ShenHeOutput>> results = new ResultDto<List<Service.Dto.ShenHeOutput>>();
            using (TargetService serv = new TargetService(dbContextStr))
            {
                results = serv.ChaXunShenHeTemp();
            }
            return Json(results);
        }

        [System.Web.Http.HttpPost]
        public JsonResult<ResultDto<List<Service.Dto.ShenHeOutput>>> DeptApproval(string dept)
        {
            ResultDto<List<Service.Dto.ShenHeOutput>> results = new ResultDto<List<Service.Dto.ShenHeOutput>>();
            using (TargetService serv = new TargetService(dbContextStr))
            {
                results = serv.ChaXunShenHeDepartment(dept);
            }
            return Json(results);
        }

        /// <summary>
        /// 获取公司报表.
        /// </summary>
        /// <returns></returns>
        [System.Web.Http.HttpPost]
        public JsonResult<ResultDto<bool>> UpdateApprovalStatus(int id, string ApprovalStatus)
        {
            ResultDto<bool> results = new ResultDto<bool>();
            using (BSCReports_DPService serv = new BSCReports_DPService(dbContextStr))
            {
                results = serv.UpdateApprovalStatus(id,ApprovalStatus);
            }
            return Json(results);
        }


        [System.Web.Http.HttpGet]
        public JsonResult<ResultDto<List<string>>> chaxunbanben()
        {
            ResultDto<List<string>> results = new ResultDto<List<string>>();
            
            using (BSCReports_DPService serv = new BSCReports_DPService(dbContextStr))
            {
                results = serv.GetVersion();
            }
            return Json(results);
        }

    }
}
